<?php
class ControllerMyplanCheckplan extends Controller{
	public function index(){
		
		if(isset($this->request->get["user_id"])){
		
			//check if they are friends.
			$this->load->model("myplan/user");
			$data=array();
			$data['user_id']=$this->user->getId();
			$data['friend_id']=$this->request->get["user_id"];
			$this->data["user"]=$this->model_myplan_user->getUserById($this->request->get["user_id"]);
			
			if($this->model_myplan_user->isFriend($data)){
				
				$query=array();
				
				$query["user_id"]=$this->request->get["user_id"];
			
				if(isset($this->request->get["status"])){
					$query["status"]=$this->request->get["status"];
				}else{
					$query["status"]="1";
				}
				
				$limit=10;
				
				if(isset($this->request->get["page"])){
					$page=$this->request->get["page"];
				}else{
					$page=1;
				}
				
				$query["start"]=($page-1)*$limit;
				$query["limit"]=$limit;
			
				$this->load->model("myplan/plan");
				$this->data["userplans"]=$this->model_myplan_plan->getAllPlans($query);
				$this->data['status']=$this->model_myplan_plan->getStatus($query["status"]);
				$this->data['allstatus']=$this->model_myplan_plan->getAllStatus();
				$this->data["plan_types"]=$this->model_myplan_plan->getPlanTypes();
				$plan_total=$this->model_myplan_plan->getTotalPlans($query);
				
				$this->data["link_status"]=$this->url->link("myplan/checkplan")."&user_id=".$query["user_id"]."&status=";
				
				$this->data["viewplan"]=$this->url->link("myplan/viewplan")."&user_id=".$this->request->get["user_id"]."&plan_id=";
				
				//分页
				$pagination = new Pagination();
				$pagination->total = $plan_total;
				$pagination->page = $page;
				$pagination->limit = $limit;
				$pagination->text = "P";
				$pagination->url = $this->url->link('myplan/checkplan',  $url . '&page={page}')."&status=".$query["status"]."&user_id=".$query["user_id"];
					
				$this->data['pagination'] = $pagination->render();
				
			}else{
				$this->data['information']="只有好友才能查看计划.";
			}
			
		}
		
		if (file_exists(DIR_TEMPLATE . $this->config->get('config_template') . '/template/myplan/checkplan.tpl')) 		            {
				$this->template = $this->config->get('config_template') . '/template/myplan/checkplan.tpl';
			} else {
				$this->template = 'default/template/myplan/checkplan.tpl';
			}
			
			$this->children = array(
			'myplancommon/footer',
			'myplancommon/header'
			);
											
			$this->response->setOutput($this->render());
	}	
	
	
}
?>
